/**
 * $Revision: 1.0 $
 * $Author: Eric Yang $
 * $Date: Aug 7, 2009 10:38:54 PM $
 *
 * Author: Eric Yang
 * Date  : Aug 7, 2009 10:38:54 PM
 *
 */
package com.gooex.service.organization.impl;

import java.util.List;

import org.c4j.string.StringTools;
import org.c4j.system.web.hibernate.BaseHibernateService;

import com.gooex.domain.organization.Partner;
import com.gooex.service.base.exception.PartnerException;
import com.gooex.service.organization.IPartnerManager;

/**
 * @author Eric Yang
 * @version 1.0
 */
public class PartnerManagerImpl extends BaseHibernateService implements IPartnerManager {

	public Partner getBusinessPartner(String id) {
		if (StringTools.isBlankOrNull(id))
			return null;
		return (Partner) getHibernateTemplate().get(Partner.class, id);
	}

	public List<Partner> getBusinessPartners() {
		return getHibernateTemplate().find("from BusinessPartner");
	}

	public Partner getBusinessPartnerByName(String name) {
		String hql = "from " + Partner.class.getName() + " where name=?";
		List<Partner> products = getHibernateTemplate().find(hql, name);
		if (products != null && products.size() == 1)
			return products.get(0);
		return null;
	}

	public void saveBusinessPartner(Partner product) {
		if (StringTools.isBlankOrNull(product.getId())) {
			product.setId(null);
		}
		getHibernateTemplate().saveOrUpdate(product);
	}

	public void removeBusinessPartner(Partner product) throws PartnerException {
		product = getBusinessPartner(product.getId());
		getHibernateTemplate().delete(product);
	}

}
